package com.cn.bulu.server.zhifubao.util;

import java.math.RoundingMode;
import java.text.DecimalFormat;

import org.apache.log4j.Logger;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayFundTransToaccountTransferModel;
import com.alipay.api.request.AlipayFundTransToaccountTransferRequest;
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;
import com.cn.bulu.utils.BuluResult;
import com.cn.bulu.utils.ClothCurtain.Arith;
import com.cn.bulu.utils.alipay.config.AlipayConfig;

/**
 * @author liuchaoya E-mail: 1090969255@qq.com
 * @version 创建时间：2017年7月7日 上午11:27:13 类说明
 * 用于测试时进行的一些支付或充值    提回测试人员账户
 */
public class TestWithDraw {
	
	public static void main(String[] args) {
		TestWithDraw testWithDraw = new TestWithDraw();
		testWithDraw.withDraw();
	}
	
	Logger logger = Logger.getLogger(TestWithDraw.class);
	private double money = 60;
	private String name = "李亚涛";
	private String aliNum = "15346068899";
	private String orderNum = "T20170707182047";

	public void withDraw() {
		// 实例化客户端
		AlipayClient alipayClient0 = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",
				AlipayConfig.app_id, AlipayConfig.app_private_key, "json", "utf-8", AlipayConfig.alipay_public_key,
				"RSA2");
		AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();
		AlipayFundTransToaccountTransferModel model = new AlipayFundTransToaccountTransferModel();
		// 鹿客家居的唯一提现流水号
		model.setOutBizNo(orderNum);
		// 收款方账户类型。
		model.setPayeeType("ALIPAY_LOGONID");
		// 收款方账户。
		model.setPayeeAccount(aliNum);
		// 转账金额
		DecimalFormat formater = new DecimalFormat("#0.#");
		formater.setRoundingMode(RoundingMode.FLOOR);
		logger.error(formater.format(Arith.mul(money, Arith.sub(1, 0.000))));
		model.setAmount(formater.format(Arith.mul(money, Arith.sub(1, 0.000))));
		// 付款方真实姓名
		model.setPayerShowName("郑州鹿客互联网科技有限公司");
		// 收款方真实姓名（最长支持100个英文/50个汉字）。
		model.setPayeeRealName(name);
		// 转账备注
		model.setRemark("技术充值或支付订单后提出支付金额");
		// 加入请求头
		request.setBizModel(model);
		AlipayFundTransToaccountTransferResponse response = null;
		try {
			Thread.sleep(3000);
			response = alipayClient0.execute(request);
			if (response.isSuccess()) {// 请求成功
				System.err.println("================提现成功===============");
			} else {
				System.err.println("================提现异常===============");
			}
		} catch (AlipayApiException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			logger.error("支付宝请求暂停3秒==========================");
			e.printStackTrace();
		}
	}

}
